<template>
	<view class="container">
		<view class="bg-colore"></view>
		<view class="content">
			<view class="wrap">
				<view class="logo">
					<uni-file-picker :value="tximage" file-mediatype="image" @select="select" limit="1" :disable-preview="true"
						class="logobtn" :image-styles="{'height': '220rpx', 'width' : '320rpx' }">
						<image :src="$public.imgageUrl(qiYeData.businessLicense)" mode="scaleToFill" class="logoimg"></image>

					</uni-file-picker>
					<view class="logobottom">
						可点击修改
					</view>
				</view>
				<uni-list class="center-list">
					<uni-list-item title="企业名称" :rightText="qiYeData.tenementName" />
					<uni-list-item title="联系人" :rightText="qiYeData.name" />
					<uni-list-item title="手机号" :rightText="qiYeData.phone" />
					<uni-list-item title="入驻时间" :rightText="qiYeData.createTime.split(' ')[0]" />
					<uni-list-item title="营业时间" :rightText="qiYeData.busTime" showArrow @click="openYysj" clickable />
				</uni-list>
				<view class="xiabtn">
					<view class="btncss" @click="btnclick">
						保存
					</view>
				</view>
			</view>

		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				qiYeData: {
					businessLicense: "",
					tenementName: "",
					name: "",
					phone: "",
					createTime: "",
					busTime: ""
				},
				tximage: [],
			};
		},
		onLoad() {
			this.getShangJiaData()
		},
		methods: {
			async select(e) {
				console.log("select", e)
				e.tempFilePaths.forEach(item => {
					this.tximage.push({
						url: item,
						name: "",
						path: item,
					})
					this.uploadImg(item)
				})
			},
			async uploadImg(item) {
				if (!item) return false;
				const [err, {
					data
				}] = await uni.uploadFile({
					url: this.baseUrl + '/api/upload',
					filePath: item,
					name: 'file',
				});
				let res = JSON.parse(data);
				// this.$ref.tximage.clearFiles()
				// this.tximage = []
				this.tximage.splice(0, 1)
				this.qiYeData.businessLicense = res.fileName
				// this.addUserInfo("image")

			},
			getShangJiaData() {
				this.$public.htmlPost("/api/getShangJiaData").then((res) => {
					console.log("getShangJiaData", res.data)
					let data = res.data;
					if (data.code == 0) {
						this.qiYeData = data.data
					}
				})
			},
			openYysj() {
				let that = this
				uni.showModal({
					editable: true,
					title: "修改营业时间",
					placeholderText: "请输入营业时间",
					success: function(res) {
						if (res.confirm) {
							// console.log('用户点击确定', res);
							that.qiYeData.busTime = res.content
						}
					}
				})
			},
			btnclick() {
				this.$public.htmlPost("/api/updateShangJiaData", {
					image: this.qiYeData.businessLicense,
					busTime: this.qiYeData.busTime
				}).then((res) => {
					console.log("updateShangJiaData", res.data)
					let data = res.data;
					if (data.code == 0) {
						this.$api.msg("保存成功");
						return false
					} else {
						this.$api.msg("保存失败，内容有误");
						return false
					}
				})

			}
		}
	}
</script>

<style lang="scss" scoped>
	.wrap {
		padding: $uni-wrap-padding;
	}

	/deep/.uni-list {
		background: none;

		&.center-list {
			padding-bottom: 40rpx;
		}

		.uni-list-item {
			background: none;
			margin-bottom: 30rpx;
			border-radius: 16rpx 16rpx 16rpx 16rpx;
		}

		.uni-list-item__content-title {
			color: #999999;
			font-size: 30rpx;
		}

		.uni-list-item__extra-text {
			color: #333333;
			font-size: 30rpx;
		}

	}

	.logo {
		text-align: center;
		margin: 40rpx 0;

		.logoimg {
			width: 300rpx;
			height: 200rpx;
		}

		.logobottom {
			font-size: 28rpx;
			margin-top: 24rpx;
			text-align: center;
			color: #333333;
		}
	}

	/deep/.uni-file-picker__container {
		justify-content: center;
	}
</style>